package com.mybatis.boost.id;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.annotation.PostConstruct;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;

/**
 * @author jearton
 * @since 2017/2/7
 */
@Configuration
@Order(HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(IdGeneratorProperties.class)
public class IdAutoConfiguration {

    private final IdGeneratorProperties idGeneratorProperties;

    @Autowired
    public IdAutoConfiguration(IdGeneratorProperties idGeneratorProperties) {
        this.idGeneratorProperties = idGeneratorProperties;
    }

    @PostConstruct
    public void init() {
        IdHelper.reload(idGeneratorProperties.getNodeId());
    }
}
